package com.cj.webapp.account.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cj.webapp.account.pojo.ConstantParamter;
import com.cj.webapp.account.pojo.LoginPersonDto;
import com.cj.webapp.account.service.AccountPersonServiceImpl;
import com.cj.webapp.common.sign.SignVerifyHandle;
import com.cj.webapp.common.utils.MapDetail;
import com.cj.webapp.common.utils.UtilDatetime;

/**
 *
 * 个人会员开户
 * Created by dell on 2017/12/25.
 */

//@WebServlet(name = "addPerson",urlPatterns ={"/account/addEnterprise"})
public class AccountPersonServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	request.setCharacterEncoding("utf-8");
    	response.setContentType("text/html;charset=utf-8");
		//HttpSession session = request.getSession();
    	//response.setCharacterEncoding("utf-8");
    	LoginPersonDto personDto =new LoginPersonDto();
        String custNm=request.getParameter("custNm");
        String idType=request.getParameter("idType");
		String phone=request.getParameter("phone");
		String idNo=request.getParameter("idNo");
		String platefmCusId=request.getParameter("platfmCustId");
		String channelCode=request.getParameter("channelCode");
		String email=request.getParameter("email");
		String province=request.getParameter("province");
		String city=request.getParameter("city");
		String role=request.getParameter("role");
		String sex =request.getParameter("sex");
		String birthDt =request.getParameter("birthDt");
		String inviteCd =request.getParameter("inviteCd");
		String nickNm =request.getParameter("nickNm");
		String wechatnm=request.getParameter("wechatnm");
		String bankAccNo=request.getParameter("bankAccNo");
		String bankNm=request.getParameter("bankNm");
		String bankBranchNm=request.getParameter("bankBranchNm");
		String bankProv=request.getParameter("bankProv");
		String bankCity=request.getParameter("bankCity");
		String bankCardOfMobile=request.getParameter("bankCardOfMobile");
		String cardType =request.getParameter("cardType");
		String remark =request.getParameter("remark");
		personDto.setCustNm(custNm);
		personDto.setIdType(idType);
		personDto.setPhone(phone);
		personDto.setIdNo(idNo);
		personDto.setPlatfmCustId(MapDetail.resMap.get("platfmCustId").toString());
		personDto.setChannelCode(channelCode);
		personDto.setEmail(email);
		personDto.setProvince(province);
		personDto.setCity(city);
		personDto.setRole(role);
		personDto.setSex(sex);
		personDto.setBirthDt(birthDt);
		personDto.setInviteCd(inviteCd);
		personDto.setNickNm(nickNm);
		personDto.setWechatnm(wechatnm);
		personDto.setSource(MapDetail.resMap.get("source").toString());
		personDto.setBankAccNo(bankAccNo);
		personDto.setBankNm(bankNm);
		personDto.setBankBranchNm(bankBranchNm);
		personDto.setBankProv(bankProv);
		personDto.setBankCity(bankCity);
		personDto.setBankCardOfMobile(bankCardOfMobile);
		personDto.setCardType(cardType);
		personDto.setRemark(remark);
		SignVerifyHandle signVerifyHandle=new SignVerifyHandle();
		String s = signVerifyHandle.signData(ConstantParamter.VIP_NUM, JSON.toJSONString(personDto));

		SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
		JSONObject jsonhead = new JSONObject(true);
		JSONObject jsonbody = new JSONObject(true);

		// head
		jsonhead.put("serviceName","PERSON_REGISTER");//接口名称
		jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
		jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
		jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
		jsonhead.put("requestNo", "011"+df.format(new Date()));//请求流水(贯穿整个请求返回)
		jsonhead.put("signData",s);
		jsonhead.put("sessionId",MapDetail.resMap.get("sessionId").toString());//sessionId
		jsonhead.put("source",MapDetail.resMap.get("source").toString());//source
		jsonhead.put("token",MapDetail.resMap.get("token").toString());
		jsonhead.put("version",ConstantParamter.VERSION_ID);//版本号
		jsonhead.put("rebackUrl",ConstantParamter.ACCOUNT_REBACK_Url);//业务处理结果返回url

		request.setAttribute("head",JSON.toJSONString(jsonhead));
		request.setAttribute("body",JSON.toJSONString(personDto));
		request.setAttribute("urlString",ConstantParamter.GATE_WAY_URL);

		request.getRequestDispatcher("/page/index/registerPost.jsp").forward(request,response);

	} 
   
}
